Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SDL_RenderDebugTextF & SDL_RenderDebugTextV #11602

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

williamistGitHub
Copy link

Description

SDL_RenderDebugText is a useful function to quickly put debug text on the screen, but provides no easy way to display other data useful for debugging such as numbers. In an attempt to rectify that, I've added SDL_RenderDebugTextF as well as SDL_RenderDebugTextV. These functions allow you to pass in a format string as well as the formatting arguments (either variadicly or as a va_list respectively) and will run them through SDL_vsnprintf before itself calling SDL_RenderDebugText to do the actual rendering. This should hopefully make it easier to quickly put useful data such as framerate, particle count, or whatever else is needed onto the screen without having to format them into a string manually.

I'm not too sure if I've done everything correctly here (mainly I wasn't sure what to put in the \since documentation tags, I just used 3.1.7 as that's what was in CMakeLists.txt), but hopefully it's not too bad :)

Existing Issue(s)

No issue.

@slouken slouken requested a review from icculus December 7, 2024 16:49
@slouken slouken added this to the 3.2.0 milestone Dec 7, 2024
@slouken
Copy link
Collaborator

slouken commented Dec 7, 2024

@icculus, is this something we want?

@icculus
Copy link
Collaborator

icculus commented Dec 10, 2024

Mmmm...I don't think we should add this. It's trivial enough to use SDL_snprintf() directly.

@williamistGitHub
Copy link
Author

Potentially, but I feel using a single function over two is cleaner and less verbose, especially if you're repeatedly formatting and rendering debug text to display multiple lines of data. If you feel like it isn't worth the extra functions though, that's understandable.

@slouken
Copy link
Collaborator

slouken commented Dec 11, 2024

I think the F variant is worth adding, but I don't think this is something people should generally be wrapping other format print functions around, so let's drop the V variant.

@icculus, technically it's an ABI break, but can we just switch the existing function to take format params instead of a single text pointer? 99.99% of uses will not contain '%', and should be safe as-is.

@icculus
Copy link
Collaborator

icculus commented Dec 11, 2024

I was thinking it would be better if the one function just accepted format args, had we thought of that before shipping a prerelease. We can just add a second function, and reduce it in SDL4. :)

@icculus
Copy link
Collaborator

icculus commented Dec 11, 2024

Okay, we did some experimentation, and we think that just changing the existing function to take a format string is binary compatible across a bunch of architectures, and the risk overall of changing this is small at this point, as it's only in one prerelease, so we're going to take a shot at it.

This is totally pushing the boundaries on ABI stability, but we think it's the correct technical decision.

I'm going to merge this PR so you get credit for the work, then make the changes on top of that.

williamistGitHub and others added 3 commits December 11, 2024 14:59
This should make it easier to quickly put important numbers and such on
the screen without having to format them into a string manually.
@icculus icculus force-pushed the formatted-debug-text branch from 329f619 to 567d87c Compare December 11, 2024 20:16
@icculus
Copy link
Collaborator

icculus commented Dec 11, 2024

Okay, this is rebased and updated to just have the original function offer printf-style formatting.

Let the builders and @slouken check it, then go ahead and merge!

@@ -2519,6 +2521,13 @@ extern SDL_DECLSPEC bool SDLCALL SDL_GetRenderVSync(SDL_Renderer *renderer, int
*
* The text is drawn in the color specified by SDL_SetRenderDrawColor().
*
* **WARNING**: Note that in SDL 3.1.6, this function accepted a single string
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove this warning. We can put it in the patch notes, but we don't need to carry it forward.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that's fine.

src/dynapi/SDL_dynapi.c Outdated Show resolved Hide resolved
if (result >= 0 && (size_t)result >= sizeof(buf)) { \
str = NULL; \
va_start(ap, fmt); \
result = SDL_vasprintf(&str, fmt, ap); \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need the jump table version of this?

@slouken
Copy link
Collaborator

slouken commented Dec 11, 2024

I'm looking at these changes, wondering if maybe we should just have a separate function. Having to add "%s" to all the existing call sites seems clunky.

@icculus
Copy link
Collaborator

icculus commented Dec 11, 2024

This brings me back to "they can just call snprintf and hand us a string" then. :/

@slouken
Copy link
Collaborator

slouken commented Dec 11, 2024

This brings me back to "they can just call snprintf and hand us a string" then. :/

Fair enough. :)

@icculus icculus closed this Dec 11, 2024
@williamistGitHub
Copy link
Author

Just saw this, ah well, too bad I suppose. Maybe next time :)

@icculus
Copy link
Collaborator

icculus commented Dec 12, 2024

Your patch was well-constructed, to be clear, we just decided against adding the API here.

@slouken
Copy link
Collaborator

slouken commented Dec 12, 2024

It also doesn’t mean we won’t add it later, we are just trying to keep things lean and focused for release.

@slouken slouken reopened this Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants